<%--
 *  File:    ActivityManageDoctorPop.jsp
 *  @Author: saraxia
 *  Date:    2012/04/11
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>



<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.ActivityManageDoctorPop");  
%>

<% //--------------------------------------  variant and initialization --%>
<%
String privilegeCode = "All";
String strTableName = "v_avtivitymanagedoctor";
String strModuleName = "COM";
String contextPath = request.getContextPath();

%>



<%
  	//get current userinfo
  	HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
  	Integer nCurOrgId = (Integer)CurUserInfo.get("orgid");
  	String orgid = CurUserInfo.get("orgid").toString();
  	String strCurUserName = (String)CurUserInfo.get("username");
  	Integer nCurdoctorid = (Integer)CurUserInfo.get("doctorid");
  	String isPrimaryAdmin = (String)CurUserInfo.get("isprimaryadmin");
  	if(isPrimaryAdmin == null)
  	{
    	isPrimaryAdmin = "";
  	} 
  	//give permission
  	boolean bCanUpdatePrimaryAdmin = true;
  	if(!isPrimaryAdmin.equalsIgnoreCase("Y"))
  	{
    	bCanUpdatePrimaryAdmin = false;
  	} 
  	
  	
%>

<% //--------------------------------------  include files list --%>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>


<html>
<head>
<title>ActivityManageDoctorPop</title>
<PageFlow:CheckPageFlow pageName="p_activitydoctorsummary"/>
<%@ include file="/inc/InitEdit.inc" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/FuncLib.js"></script>
<script language="JavaScript" src="../../js/SummaryDivision.js"></script>
<script>
isRunning=false;
</script>
<%@ include file="/inc/SummaryDivision.inc" %>

<% //--------------------------------------  output variant from pageflow --%>
<%

  	Vector searchresults  = (Vector)pageContext.getAttribute("searchresults");
  	if(searchresults  == null)
  		searchresults  = new Vector();
  	
  	int totalsize  =  searchresults.size();
  	
  	String userids =  (String)pageContext.getAttribute("userids");
%>
<script>

function clickRow(obj,idx)
{
  var cform = document.cform;
  cform.id.value = eval('obj.all.id'+idx).value;
}

function page_done(){
	   for(var i = 0; i <<%=totalsize%>; i++){  
	    if(document.getElementById('doctorid'+i).checked){
	      	if(isEmpty(document.cform.selecteddoctorid.value)){
	        	document.cform.selecteddoctorid.value = document.getElementById('doctorid'+i).value;
	      	}else{
	      	    document.cform.selecteddoctorid.value = document.cform.selecteddoctorid.value + "," + document.getElementById('doctorid'+i).value;;
	      	}
	        if(isEmpty(document.cform.selecteddoctorcode.value)){
	        	document.cform.selecteddoctorcode.value = document.getElementById('doctorcode'+i).value;
	      	}else{
	        	document.cform.selecteddoctorcode.value = document.cform.selecteddoctorcode.value + "," + document.getElementById('doctorcode'+i).value;;
	      	}
	      	if(isEmpty(document.cform.selecteddoctorname.value)){
	        	document.cform.selecteddoctorname.value = document.getElementById('doctorname'+i).value;
	      	}else{
	        	document.cform.selecteddoctorname.value = document.cform.selecteddoctorname.value + "," + document.getElementById('doctorname'+i).value;;
	      	}
	      	if(isEmpty(document.cform.selectedorgcode.value)){
	        	document.cform.selectedorgcode.value = document.getElementById('orgcode'+i).value;
	      	}else{
	        	document.cform.selectedorgcode.value = document.cform.selectedorgcode.value + "," + document.getElementById('orgcode'+i).value;;
	      	}
	      	if(isEmpty(document.cform.selectedorgname.value)){
	        	document.cform.selectedorgname.value = document.getElementById('orgname'+i).value;
	      	}else{
	        	document.cform.selectedorgname.value = document.cform.selectedorgname.value + "," + document.getElementById('orgname'+i).value;;
	      	}
	      	if(isEmpty(document.cform.selectestatusname.value)){
	        	document.cform.selectestatusname.value = document.getElementById('statusname'+i).value;
	      	}else{
	        	document.cform.selectestatusname.value = document.cform.selectestatusname.value + "," + document.getElementById('statusname'+i).value;;
	      	}	      		      	
	      }
	   }
	   opener.page_setdoctors(document.cform.selecteddoctorid.value,document.cform.selecteddoctorcode.value,document.cform.selecteddoctorname.value,document.cform.selectedorgcode.value,document.cform.selectedorgname.value,document.cform.selectestatusname.value);  
	   window.close();
	}



function page_close(){
	window.close();
}


function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  editform.action = "ActivityManageDoctorPop.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();  
}

function clickCheckBox(obj){
	if(cform.numrows.value == 0){
		cform.selectedids.checked=obj.checked;
	}else if(cform.numrows.value >= 1){
		var j=0;
		for(var i=0;i<Number(cform.numrows.value);i++){
			var idchk=document.getElementById('doctorid'+j);
			if(idchk){
				idchk.checked=obj.checked;
			}
			j++;
		}
	}
}
function clearCheckFlag(obj){
	if(!obj.checked){
		cform.checkallbox.checked=false;
	}
}


</script>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

	<% //--------------------------------------  hidden form variant --%>
	<form name="cform" method="post" action="<%=contextPath %>/Dispatcher"  target="_parent">
      <input type="hidden" name="pagename" value="p_activitydoctorsummary">
    <input type="hidden" name="actionname">
    <input type="hidden" name="numrows" value="<%=totalsize%>">
    
    <input type="hidden" name="userids" value="<%=userids%>">
    
    <custom:hidden property="selecteddoctorid"/> 
	<custom:hidden property="selecteddoctorcode"/>
	<custom:hidden property="selecteddoctorname"/>
	<custom:hidden property="selectedorgcode"/>
	<custom:hidden property="selectedorgname"/>
	<custom:hidden property="selectestatusname"/>
	<custom:hidden property="activitymanageid"/>
 
	<% //--------------------------------------  page location --%>
	<%@ include file="/inc/PageLocation.inc" %>
	
	<table width="100%" cellspacing="0" cellpadding="0" border="0">
        
		  <tr>
		      <td class="summary_top">
		          <table width="100%" border="0" cellspacing="0">
		      	   <%@ include file="/inc/SummarySearch.inc" %>
		          </table>
		      </td>
		  </tr>        
   <tr>
    <td>       
        <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="0">
         <tr class="deepblue-left" >
			<td width="5%" class="title_center">
				<%if(totalsize > 0){ %>
					<input type="checkbox" name="checkallbox" class="checkbox"  onclick="clickCheckBox(this)">
				<%}else{ %>
					&nbsp;
				<%} %>
			</td>
            <td width="10%" class="title_center"><a href="javascript:page_summary('orderby','doctorcode')"><%= label.getLabelName("L_ContactCode") %></a></td>
            <td width="10%" class="title_center"><a href="javascript:page_summary('orderby','doctorname')"><%= label.getLabelName("L_ContactNameCN") %></a></td>
            <td width="15%" class="title_center"><a href="javascript:page_summary('orderby','orgcode')"><%= label.getLabelName("L_OwnerOrg")+label.getLabelName("L_Code") %></a></td>
            <td width="30%" class="title_center"><a href="javascript:page_summary('orderby','orgname')"><%= label.getLabelName("L_OwnerOrg")+label.getLabelName("L_ItemName1") %></a></td>
            <td width="10%" class="title_center"><a href="javascript:page_summary('orderby','statusname')"><%= label.getLabelName("L_Status") %></a></td>
             
       	</tr>
        
        <% //--------------------------------------  default value definition --%>
        <%
        	int i = 0;
            String strClassType = new String();   
            Integer nDefaultdoctorid = null; 
            String strIsPrimaryAdmin = "";
            boolean bHasChecked = false;   
            String strDefaultIsDisabled="";
        		String strDefaultUserName="";  
        		String strDefaultDoctorCode="";
        		String strDefaultOrgName="";
        		String strDefaultOrgCode="";
        		String strDefaultstatus= "";  
        		
      	%>
        
        <% //--------------------------------------  loop results --%>
        <logic:iterate id="usersum" collection="<%= searchresults  %>" indexId="idx">                      
        <%
        	HashMap userMap = (HashMap)pageContext.getAttribute("usersum"); 
          
            String strIsDisabled = new String("");
            String strIsChecked = new String("");
            
            if(i%2 == 1)
            {
              	strClassType = "td-listrom";
            }else{                    
              	strClassType = "";
            }
            if(!bHasChecked)
            {
                strIsChecked = "Checked";
                bHasChecked = true;
                nDefaultdoctorid = (Integer)(userMap.get("doctorid"));

                strDefaultUserName= (String)(userMap.get("doctorname"));
                strDefaultDoctorCode= (String)(userMap.get("doctorcode"));
                strDefaultOrgName= (String)(userMap.get("orgname"));
                strDefaultOrgCode= (String)(userMap.get("orgcode"));
                strDefaultstatus= (String)(userMap.get("statusname"));
                strDefaultIsDisabled = strIsDisabled;
            }   
            i++;                         
          %>
          
     	<tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'"  class="none"> 
        	<!-- 
        	<td width="5%" class="<%=JspHelper.filterNull( strClassType )%>">
            	<input type="radio" id="user<%=JspHelper.filterNull( i )%>" name="checkuser" <%=JspHelper.filterNull( strIsDisabled )%> value=<%=JspHelper.filterNull( userMap.get("doctorid") )%> class="checkbox" <%=JspHelper.filterNull( strIsChecked )%>>
            </td>
        	 -->
        	<td width="5">
            		<input id="doctorid<%=idx %>" type="checkbox" name="deptid" value="<%=JspHelper.filterNull( userMap.get("doctorid") )%>" class="checkbox" onclick="clearCheckFlag(this)">
          	</td>
          	<td>
            		<custom:write name="usersum" property="doctorcode" nbsp="true"/>
            </td>
            <td>
            		<custom:write name="usersum" property="doctorname" nbsp="true"/>
            </td>
            <td>
            	    <custom:write name="usersum" property="orgcode" nbsp="true"/>
            </td>
            <td>
            	    <custom:write name="usersum" property="orgname" nbsp="true"/>
            </td>
            <td>
            	    <custom:write name="usersum" property="statusname" nbsp="true"/>
            </td>  
                    <custom:hidden name="usersum" property="doctorcode" colIndex="<%= idx %>"  />
              		<custom:hidden name="usersum" property="doctorname" colIndex="<%= idx %>" />
              		<custom:hidden name="usersum" property="orgcode" colIndex="<%= idx %>" />
              		<custom:hidden name="usersum" property="orgname" colIndex="<%= idx %>" />
              		<custom:hidden name="usersum" property="statusname" colIndex="<%= idx %>" />          
          	<!-- 
            <td  class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("doctorcode") )%></td>
            <td class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("doctorname") )%></td>
            <td  class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("orgcode") )%></td>
            <td  class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("orgname") )%></td>
            <td class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("statusname") )%></td>
          	 -->
     	</tr>
        </logic:iterate>                   
        
        <!-- 
        <input type="hidden" name="doctorid" value="<%=JspHelper.filterNull( nDefaultdoctorid )%>">
		<input type="hidden" name="doctorname" value="<%=JspHelper.filterNull( strDefaultUserName )%>"> 
		<input type="hidden" name="doctorcode" value="<%=JspHelper.filterNull( strDefaultDoctorCode )%>"> 
		<input type="hidden" name="orgname" value="<%=JspHelper.filterNull( strDefaultOrgName )%>"> 
		<input type="hidden" name="orgcode" value="<%=JspHelper.filterNull( strDefaultOrgCode )%>"> 
 		<input type="hidden" name="statusname" value="<%=JspHelper.filterNull( strDefaultstatus )%>"> 
         -->
     
    				
        <% //--------------------------------------  flipping page --%>
    	<%@ include file="/inc/SummaryAction.inc" %>
          
        </table>
        
        <% //--------------------------------------  page operation button --%>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        	<tr> 
            	<td class="summary_top" ></td>
          	</tr>
          	<tr> 
              <td class="td_center">
                <a onclick="page_done();"><custom:button type="1" label="L_Ok" imgsrc="add.gif" border="0" style="width:60"/></a>
              	<a onclick="page_close();"><custom:button type="1" label="L_Close" imgsrc="close.gif" border="0" style="width:60"/></a>
              </td>
          	</tr>
        </table>
        
  	</td>
</tr>
</table>
</form>
</body>
</html>
<script>
isRunning=false;
</script>

